package com.yonyou.gmmc.service.forum.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.marketing.common.constants.CommonConstant;
import org.marketing.common.constants.ResultMsgConstants;
import org.marketing.common.dto.forum.ForumTopicDto;
import org.marketing.common.dto.forum.ForumTypeDto;
import org.marketing.common.util.CheckUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.yonyou.gmmc.common.annotation.ParamValid;
import org.marketing.common.Response;
import com.yonyou.gmmc.service.forum.constant.ForumConstant;
import com.yonyou.gmmc.service.forum.model.ImgListDto;
import com.yonyou.gmmc.service.forum.model.TmForumBoard;
import com.yonyou.gmmc.service.forum.model.TmForumImg;
import com.yonyou.gmmc.service.forum.model.TtForumReply;
import com.yonyou.gmmc.service.forum.model.TtForumTopic;
import com.yonyou.gmmc.service.forum.service.ForumService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(value = ForumConstant.BASE_PATH + "/" + ForumConstant.VERSION)
@Api("论坛API")
public class ForumController {

	private Logger logger = Logger.getLogger(ForumController.class);

	@Autowired
	private ForumService forumService;

	/**
	 * 获取论坛版块类型
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getBoardType", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "获取论坛版块类型", notes = "获取论坛版块类型")
	public Response<List<ForumTypeDto>> getBoardType() throws Exception {
		try {
			logger.info("查询论坛版块类型开始");
			List<ForumTypeDto> dtoList = forumService.getBoardType();
			logger.info("查询论坛版块类型结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, dtoList, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 获取论坛版块类型PC
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getBoardTypePC", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "获取论坛版块类型PC", notes = "获取论坛版块类型PC")
	public Response<List<ForumTypeDto>> getBoardTypePC() throws Exception {
		try {
			logger.info("查询论坛版块类型PC开始");
			List<ForumTypeDto> dtoList = forumService.getBoardTypePC();
			logger.info("查询论坛版块类型PC结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, dtoList, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 更多版块
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryBoardList", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "获取更多版块列表", notes = "获取更多版块列表")
	public Response<List<ForumTypeDto>> queryBoardList() throws Exception {
		try {
			logger.info("获取更多版块列表开始");
			List<ForumTypeDto> dtoList = forumService.queryBoardList();
			logger.info("获取更多版块列表结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, dtoList, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 获取标题列表
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getTopicList", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "获取标题列表", notes = "获取标题列表")
	public Response<PageInfo<ForumTopicDto>> getTopicList(
			@RequestParam(required = false, defaultValue = "10") Integer pageNum,
			@RequestParam(required = false, defaultValue = "10") String pageSize,
			@RequestParam(required = false, defaultValue = "") Long topicId, // 标题ID
			@RequestParam(required = false, defaultValue = "") Long boardId, // 版块ID
			@RequestParam(required = false, defaultValue = "") Long typeId, // 类型ID
			@RequestParam(required = false, defaultValue = "") String title, // 搜索内容
			@RequestParam(required = false, defaultValue = "") Long ifEssence, // 是否精华帖
																				// ，1：是精华帖
			@RequestParam(required = true, defaultValue = "10") Integer hotType, // 热帖切换，0：最新发布，1
																					// ：24小时热帖，7：本周热帖，10：置顶排序查询查询
			HttpServletRequest request) throws Exception {
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			if (CheckUtil.NullOrEmpty(openId)) {
				String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
				if (!CheckUtil.NullOrEmpty(userId)) {
					openId = forumService.selectopenIdByUserId(userId);
				}
			}
			// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
			Map<String, Object> queryMap = new HashMap<>();
			queryMap.put("pageNum", pageNum);
			queryMap.put("pageSize", pageSize);
			queryMap.put("topicId", topicId);
			queryMap.put("boardId", boardId);
			queryMap.put("typeId", typeId);
			queryMap.put("title", title);
			queryMap.put("ifEssence", ifEssence);
			queryMap.put("hotType", hotType);
			logger.info("查询获取标题列表开始openId:" + openId);
			PageInfo<ForumTopicDto> page = forumService.getTopicList(queryMap, openId);
			logger.info("查询获取标题列表结束");
			return new Response<PageInfo<ForumTopicDto>>(ResultMsgConstants.RESULT_CODE_SUCCESS, page, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 获取回复列表
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getReplyList", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "获取回复列表", notes = "获取回复列表")
	public Response<PageInfo<TtForumReply>> getReplyList(
			@RequestParam(required = false, defaultValue = "10") Integer pageNum,
			@RequestParam(required = false, defaultValue = "10") String pageSize,
			@RequestParam(required = true, defaultValue = "") Long topicId, HttpServletRequest request)
			throws Exception {
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			if (CheckUtil.NullOrEmpty(openId)) {
				String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
				if (!CheckUtil.NullOrEmpty(userId)) {
					openId = forumService.selectopenIdByUserId(userId);
				}
			}
			// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
			Map<String, Object> queryMap = new HashMap<>();
			queryMap.put("pageNum", pageNum);
			queryMap.put("pageSize", pageSize);
			queryMap.put("topicId", topicId);
			logger.info("查询获取回复列表开始");
			PageInfo<TtForumReply> page = forumService.getReplyList(queryMap, openId);
			logger.info("查询获取回复列表结束");
			return new Response<PageInfo<TtForumReply>>(ResultMsgConstants.RESULT_CODE_SUCCESS, page, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 获取帖子详情
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/topicDetails", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "获取帖子详情", notes = "获取帖子详情")
	public Response<ForumTopicDto> topicDetails(@RequestParam(required = false, defaultValue = "") Long topicId,
			HttpServletRequest request) throws Exception {
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			if (CheckUtil.NullOrEmpty(openId)) {
				String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
				if (!CheckUtil.NullOrEmpty(userId)) {
					openId = forumService.selectopenIdByUserId(userId);
				}
			}
			// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
			logger.info("获取帖子详情开始,openId:" + openId);
			ForumTopicDto result = forumService.topicDetails(topicId, openId);
			logger.info("获取帖子详情结束");
			return new Response<ForumTopicDto>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 统计阅读数量
	 * 
	 * @param topicId
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/saveReadingNum", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "统计阅读数量", notes = "统计阅读数量")
	public Response<Map<String, Object>> saveReadingNum(@RequestParam(required = true, defaultValue = "") Long topicId,
			HttpServletRequest request) throws Exception {
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			if (CheckUtil.NullOrEmpty(openId)) {
				String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
				if (!CheckUtil.NullOrEmpty(userId)) {
					openId = forumService.selectopenIdByUserId(userId);
				}
			}
			// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
			// logger.info("统计阅读数量开始，topicId："+topicId+"，openId："+openId);
			Map<String, Object> result = forumService.saveReadingNum(topicId, openId);
			logger.info("统计阅读数量结束");
			return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 统计转发数量
	 * 
	 * @param topicId
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/saveTranspondNum", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "统计转发数量", notes = "统计转发数量")
	public Response<Map<String, Object>> saveTranspondNum(
			@RequestParam(required = true, defaultValue = "") Long topicId, HttpServletRequest request)
			throws Exception {
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			if (CheckUtil.NullOrEmpty(openId)) {
				String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
				if (!CheckUtil.NullOrEmpty(userId)) {
					openId = forumService.selectopenIdByUserId(userId);
				}
			}
			// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
			// logger.info("统计转发数量开始，topicId："+topicId+"，openId："+openId);
			Map<String, Object> result = forumService.saveTranspondNum(topicId, openId);
			logger.info("统计转发数量结束");
			return new Response<Map<String, Object>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 我的论坛
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryMyForum", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "我的论坛", notes = "我的论坛")
	public Response<Map<String, Object>> queryMyForum(HttpServletRequest request) throws Exception {
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			if (CheckUtil.NullOrEmpty(openId)) {
				String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
				if (!CheckUtil.NullOrEmpty(userId)) {
					openId = forumService.selectopenIdByUserId(userId);
				}
			}
			// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
			logger.info("查询开始，我的论坛，我的openId为：" + openId);
			Map<String, Object> resultMap = forumService.queryMyForum(openId);
			logger.info("查询我的论坛结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, resultMap, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 我的帖子
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryMyTopic", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "我的帖子", notes = "我的帖子")
	public Response<PageInfo<ForumTopicDto>> queryMyTopic(
			@RequestParam(required = false, defaultValue = "10") Integer pageNum,
			@RequestParam(required = false, defaultValue = "10") String pageSize, HttpServletRequest request)
			throws Exception {
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			if (CheckUtil.NullOrEmpty(openId)) {
				String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
				if (!CheckUtil.NullOrEmpty(userId)) {
					openId = forumService.selectopenIdByUserId(userId);
				}
			}
			// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
			Map<String, Object> queryMap = new HashMap<>();
			queryMap.put("pageNum", pageNum);
			queryMap.put("pageSize", pageSize);
			queryMap.put("hotType", 0);
			queryMap.put("openId", openId);
			// logger.info("查询我的帖子开始，我的openId为："+openId);
			PageInfo<ForumTopicDto> page = forumService.queryMyTopic(queryMap, openId);
			logger.info("查询我的帖子结束");
			return new Response<PageInfo<ForumTopicDto>>(ResultMsgConstants.RESULT_CODE_SUCCESS, page, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 我的评论
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryMyReply", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "我的评论", notes = "我的评论")
	public Response<PageInfo<ForumTopicDto>> queryMyReply(
			@RequestParam(required = false, defaultValue = "10") Integer pageNum,
			@RequestParam(required = false, defaultValue = "10") String pageSize, HttpServletRequest request)
			throws Exception {
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			if (CheckUtil.NullOrEmpty(openId)) {
				String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
				if (!CheckUtil.NullOrEmpty(userId)) {
					openId = forumService.selectopenIdByUserId(userId);
				}
			}
			// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
			Map<String, Object> queryMap = new HashMap<>();
			queryMap.put("pageNum", pageNum);
			queryMap.put("pageSize", pageSize);
			queryMap.put("openId", openId);
			// logger.info("查询我的评论开始，openId为："+openId);
			PageInfo<ForumTopicDto> page = forumService.queryMyReply(queryMap, openId);
			logger.info("查询我的评论结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, page, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 我的转发
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryMyTranspond", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "我的转发", notes = "我的转发")
	public Response<PageInfo<ForumTopicDto>> queryMyTranspond(
			@RequestParam(required = false, defaultValue = "10") Integer pageNum,
			@RequestParam(required = false, defaultValue = "10") String pageSize, HttpServletRequest request)
			throws Exception {
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			if (CheckUtil.NullOrEmpty(openId)) {
				String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
				if (!CheckUtil.NullOrEmpty(userId)) {
					openId = forumService.selectopenIdByUserId(userId);
				}
			}
			// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
			Map<String, Object> queryMap = new HashMap<>();
			queryMap.put("pageNum", pageNum);
			queryMap.put("pageSize", pageSize);
			// queryMap.put("openId", openId);
			// logger.info("查询我的转发开始，openId为："+openId);
			PageInfo<ForumTopicDto> page = forumService.queryMyTranspond(queryMap, openId);
			logger.info("查询我的转发结束");
			return new Response<PageInfo<ForumTopicDto>>(ResultMsgConstants.RESULT_CODE_SUCCESS, page, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 发帖
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/publishTopic", method = RequestMethod.POST)
	@ApiOperation(value = "发帖", notes = "发帖")
	@ResponseBody
	@ParamValid
	public Response<Map<String, Object>> publishTopic(@RequestParam(required = true, defaultValue = "") Long boardId,
			@RequestParam(required = true, defaultValue = "") String topicName,
			@RequestParam(required = true, defaultValue = "") String topicContent,
			// @RequestParam("imgFile") MultipartFile file,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		try {
			logger.info("查询openId开始");
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			if (CheckUtil.NullOrEmpty(openId)) {
				String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
				if (!CheckUtil.NullOrEmpty(userId)) {
					openId = forumService.selectopenIdByUserId(userId);
				}
			}
			// String openId = "oXrcfuCpMJXvTH9L38ajQmEuaoxw";
			logger.info("发帖开始，openId为：" + openId);
			TtForumTopic tmForumTopic = new TtForumTopic();
			tmForumTopic.setBoardId(boardId);
			tmForumTopic.setTopicName(topicName);
			tmForumTopic.setTopicContent(topicContent);
			Map<String, Object> result = forumService.publishTopic(openId, tmForumTopic, request);
			logger.info("发帖结束");
			// Cookie
			// response.addCookie();
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 获取帖子ID
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryTopicId", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "获取帖子ID", notes = "获取帖子ID")
	public Response<Long> queryTopicId() throws Exception {
		try {
			logger.info("获取帖子ID开始");
			Long topicId = forumService.queryTopicId();
			logger.info("获取帖子ID结束");
			return new Response<Long>(ResultMsgConstants.RESULT_CODE_SUCCESS, topicId, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 上传图片
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/uploadImg", method = RequestMethod.POST)
	@ApiOperation(value = "上传图片", notes = "上传图片")
	@ResponseBody
	@ParamValid
	public Response<Map<String, Object>> uploadImg(@RequestBody ImgListDto imgListDto, HttpServletRequest request)
			throws Exception {
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			if (CheckUtil.NullOrEmpty(openId)) {
				String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
				if (!CheckUtil.NullOrEmpty(userId)) {
					openId = forumService.selectopenIdByUserId(userId);
				}
			}
			// String openId = "oXrcfuCpMJXvTH9L38ajQmEuaoxw";
			logger.info("上传图片开始，openId为：" + openId);
			Map<String, Object> result = forumService.uploadImg(openId, imgListDto);
			logger.info("上传图片结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 上传帖子内容
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/uploadTopic", method = RequestMethod.POST)
	@ApiOperation(value = "上传帖子内容", notes = "上传帖子内容")
	@ResponseBody
	@ParamValid
	public Response<Map<String, Object>> uploadTopic(@RequestBody TtForumTopic tmForumTopic, HttpServletRequest request)
			throws Exception {
		try {
			logger.info("查询openId开始");
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			if (CheckUtil.NullOrEmpty(openId)) {
				String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
				if (!CheckUtil.NullOrEmpty(userId)) {
					openId = forumService.selectopenIdByUserId(userId);
				}
			}
			// String openId = "oXrcfuCpMJXvTH9L38ajQmEuaoxw";
			logger.info("上传帖子内容开始，openId为：" + openId);
			Map<String, Object> result = forumService.uploadTopic(openId, tmForumTopic);
			logger.info("上传帖子内容结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 发表回复
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/publishReply", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "发表回复", notes = "发表回复")
	@ResponseBody
	@ParamValid
	public Response<Map<String, Object>> publishReply(@RequestBody TtForumReply tmForumReply,
			HttpServletRequest request) throws Exception {
		try {
			String openId = request.getHeader(CommonConstant.HEADER_OPENID);
			if (CheckUtil.NullOrEmpty(openId)) {
				String userId = request.getHeader(CommonConstant.HEAD_USER_ID);
				if (!CheckUtil.NullOrEmpty(userId)) {
					openId = forumService.selectopenIdByUserId(userId);
				}
			}
			// String openId = "oXrcfuGP_a3daNZaMT_rbhvJ595I";
			logger.info("发表回复开始，openId为：" + openId);
			Map<String, Object> result = forumService.publishReply(openId, tmForumReply);
			logger.info("发表回复结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * PC后台版块查询
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryForumBoardPC", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "pc后台版块查询", notes = "pc后台版块查询")
	public Response<PageInfo<TmForumBoard>> queryForumBoardPC(
			@RequestParam(required = false, defaultValue = "10") Integer pageNum,
			@RequestParam(required = false, defaultValue = "10") String pageSize,
			@RequestParam(required = false, defaultValue = "") Long boardId,
			@RequestParam(required = false, defaultValue = "") Long boardTypeId,
			@RequestParam(required = false, defaultValue = "") String boardName,
			@RequestParam(required = false, defaultValue = "") Short deleteFlag) throws Exception {
		try {
			Map<String, Object> queryMap = new HashMap<>();
			queryMap.put("pageNum", pageNum);
			queryMap.put("pageSize", pageSize);
			queryMap.put("boardId", boardId);
			queryMap.put("boardTypeId", boardTypeId);
			queryMap.put("boardName", boardName);
			queryMap.put("deleteFlag", deleteFlag);
			logger.info("pc后台版块查询开始");
			PageInfo<TmForumBoard> result = forumService.queryForumBoardPC(queryMap);
			logger.info("pc后台版块查询结束");
			return new Response<PageInfo<TmForumBoard>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * PC后台版块图标列表
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryForumImgPC", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "PC后台版块图标列表", notes = "PC后台版块图标列表")
	public Response<List<TmForumImg>> queryForumImgPC() throws Exception {
		try {
			logger.info("PC后台版块图标列表查询开始");
			List<TmForumImg> result = forumService.queryForumImgPC();
			logger.info("PC后台版块图标列表查询结束");
			return new Response<List<TmForumImg>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * PC后台版块添加
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/addForumBoardPC", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "pc后台版块添加", notes = "pc后台版块添加")
	@ResponseBody
	@ParamValid
	public Response<Map<String, Object>> addForumBoardPC(@RequestBody TmForumBoard tmForumBoard,
			HttpServletRequest request) throws Exception {
		try {
			// String userId=request.getHeader(ForumConstant.HEADER_USERID);
			TmForumBoard tmForumBoard2 = new TmForumBoard();
			tmForumBoard2.setBoardName(tmForumBoard.getBoardName());
			tmForumBoard2.setBoardTypeId(tmForumBoard.getBoardTypeId());
			tmForumBoard2.setImgId(tmForumBoard.getImgId());
			String userId = "2";
			logger.info("pc后台版块添加开始，userId：" + userId);
			Map<String, Object> result = forumService.addForumBoardPC(tmForumBoard2, userId);
			logger.info("pc后台版块添加结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * PC后台版块编辑
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updateForumBoardPC", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "pc后台版块编辑", notes = "pc后台版块编辑")
	@ResponseBody
	@ParamValid
	public Response<Map<String, Object>> updateForumBoardPC(@RequestBody TmForumBoard tmForumBoard,
			HttpServletRequest request) throws Exception {
		try {
			// String userId=request.getHeader(ForumConstant.HEADER_USERID);
			TmForumBoard tmForumBoard2 = new TmForumBoard();
			tmForumBoard2.setBoardId(tmForumBoard.getBoardId());
			tmForumBoard2.setBoardName(tmForumBoard.getBoardName());
			tmForumBoard2.setBoardTypeId(tmForumBoard.getBoardTypeId());
			tmForumBoard2.setImgId(tmForumBoard.getImgId());
			String userId = "2";
			logger.info("pc后台版块编辑开始：userId：" + userId);
			Map<String, Object> result = forumService.updateForumBoardPC(tmForumBoard2, userId);
			logger.info("pc后台版块编辑结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * PC后台版块删除
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/deleteForumBoardPC", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "pc后台版块删除", notes = "pc后台版块删除")
	@ResponseBody
	@ParamValid
	public Response<Map<String, Object>> deleteForumBoardPC(
			@RequestParam(required = false, defaultValue = "") Long boardId, HttpServletRequest request)
			throws Exception {
		try {
			// String userId=request.getHeader(ForumConstant.HEADER_USERID);
			String userId = "2";
			logger.info("	PC后台版块删除：userId：" + userId + "版块ID：" + boardId);
			Map<String, Object> result = forumService.deleteForumBoardPC(boardId, userId);
			logger.info("	PC后台版块删除");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * PC后台帖子列表查询
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryForumTopicPC", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "PC后台帖子列表查询", notes = "PC后台帖子列表查询")
	public Response<PageInfo<ForumTopicDto>> queryForumTopicPC(
			@RequestParam(required = false, defaultValue = "10") Integer pageNum,
			@RequestParam(required = false, defaultValue = "10") String pageSize,
			@RequestParam(required = false, defaultValue = "") Long topicId, // 标题ID
			@RequestParam(required = false, defaultValue = "") Long boardId, // 版块ID
			@RequestParam(required = false, defaultValue = "") Long typeId, // 类型ID
			@RequestParam(required = false, defaultValue = "") String boardName, // 版块名称
			@RequestParam(required = false, defaultValue = "") String title, // 搜索内容
			@RequestParam(required = false, defaultValue = "") Long ifEssence, // 是否精华帖
																				// ，0：普通，1：是精华帖
			@RequestParam(required = false, defaultValue = "") Long ifTop, // 是否置顶，0：普通，1：置顶
			@RequestParam(required = false, defaultValue = "") Integer deleteFlag, // 发帖状态，0：有效，1：已删除
			@RequestParam(required = false, defaultValue = "") Long startReadCount, // 阅读数
			@RequestParam(required = false, defaultValue = "") Long endReadCount, // 阅读数
			@RequestParam(required = false, defaultValue = "") Long startTranspondCount, // 转发数
			@RequestParam(required = false, defaultValue = "") Long endTranspondCount, // 转发数
			@RequestParam(required = false, defaultValue = "") Long startReplyCount, // 评论数
			@RequestParam(required = false, defaultValue = "") Long endReplyCount// 评论数
	) throws Exception {
		try {
			Map<String, Object> queryMap = new HashMap<>();
			queryMap.put("pageNum", pageNum);
			queryMap.put("pageSize", pageSize);
			queryMap.put("topicId", topicId);
			queryMap.put("boardId", boardId);
			queryMap.put("typeId", typeId);
			queryMap.put("boardName", boardName);
			queryMap.put("title", title);
			queryMap.put("ifEssence", ifEssence);
			queryMap.put("ifTop", ifTop);
			queryMap.put("deleteFlag", deleteFlag);
			queryMap.put("startReadCount", startReadCount);
			queryMap.put("endReadCount", endReadCount);
			queryMap.put("startTranspondCount", startTranspondCount);
			queryMap.put("endTranspondCount", endTranspondCount);
			queryMap.put("startReplyCount", startReplyCount);
			queryMap.put("endReplyCount", endReplyCount);
			queryMap.put("hotType", 11);
			logger.info("PC后台帖子列表查询开始");
			PageInfo<ForumTopicDto> result = forumService.queryForumTopicPC(queryMap);
			logger.info("PC后台帖子列表查询结束");
			return new Response<PageInfo<ForumTopicDto>>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * PC后台帖子精华，删除
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updateForumTopicPC", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "PC后台帖子精华，删除", notes = "PC后台帖子精华，删除")
	@ResponseBody
	@ParamValid
	public Response<Map<String, Object>> updateForumTopicPC(@RequestBody TtForumTopic tmForumTopic, // ifEssence
																									// 0：正常，1：精华。ifTop
																									// 0：正常，1：置顶。deleteFlag
																									// 0：正常，1：删除
																									// 。
			HttpServletRequest request) throws Exception {
		try {
			// String userId=request.getHeader(ForumConstant.HEADER_USERID);
			String userId = "2";
			logger.info("PC后台帖子精华，删除开始：userId：" + userId);
			Map<String, Object> result = forumService.updateForumTopicPC(tmForumTopic, userId);
			logger.info("PC后台帖子精华，删除结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * PC后台帖子置顶
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updateTopicTopPC", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "PC后台帖子置顶", notes = "PC后台帖子置顶")
	public Response<Map<String, Object>> updateTopicTopPC(
			@RequestParam(required = true, defaultValue = "") Long topicId,
			@RequestParam(required = true, defaultValue = "") Integer ifTop,
			@RequestParam(required = false, defaultValue = "") String topDateStart,
			@RequestParam(required = false, defaultValue = "") String topDateEnd, HttpServletRequest request)
			throws Exception {
		try {
			// String userId=request.getHeader(ForumConstant.HEADER_USERID);
			String userId = "2";
			Map<String, Object> queryMap = new HashMap<>();
			queryMap.put("topicId", topicId);
			queryMap.put("ifTop", ifTop);
			queryMap.put("topDateStart", topDateStart);
			queryMap.put("topDateEnd", topDateEnd);
			queryMap.put("userId", userId);
			logger.info("PC后台帖子置顶开始：userId：" + userId);
			Map<String, Object> result = forumService.updateTopicTopPC(queryMap);
			logger.info("PC后台帖子置顶结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * PC后台查看评论
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryForumReplyPC", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "PC后台查看评论", notes = "PC后台查看评论")
	public Response<List<TtForumReply>> queryForumReplyPC(
			@RequestParam(required = true, defaultValue = "") Long topicId) throws Exception {
		try {
			logger.info("PC后台查看评论开始");
			List<TtForumReply> result = forumService.queryForumReplyPC(topicId);
			logger.info("PC后台查看评论结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * PC后台转为资讯
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/convertInformationPC", method = RequestMethod.GET)
	@ApiOperation(value = "PC后台转为资讯", notes = "PC后台转为资讯")
	public Response convertInformationPC(@RequestParam(required = true, defaultValue = "") Long topicId,
			HttpServletRequest request) throws Exception {
		try {
			logger.info("PC后台转为资讯");
			// String userId=request.getHeader(ForumConstant.HEADER_USERID);
			String userId = "2";
			logger.info("PC后台转为资讯开始,topicId:" + topicId + ",userId:" + userId);
			Integer result = forumService.convertInformationPC(topicId, userId);
			logger.info("PC后台转为资讯结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * PC后台发帖
	 * 
	 * @return
	 * @throws Exception
	 *//*
		 * @RequestMapping(value = "/publishTopicPC",method =
		 * RequestMethod.POST, produces = "application/json;charset=UTF-8")
		 * 
		 * @ApiOperation(value="PC后台发帖",notes="PC后台发帖")
		 * 
		 * @ResponseBody
		 * 
		 * @ParamValid public Response<Map<String, Object>> publishTopicPC(
		 * 
		 * @RequestBody TtForumTopic tmForumTopic, HttpServletRequest request)
		 * throws Exception { try{ //String
		 * userId=request.getHeader(ForumConstant.HEADER_USERID); String
		 * userId="2"; logger.info("PC后台发帖开始：userId："+userId); Map<String,
		 * Object> result = forumService.publishTopicPC(tmForumTopic,userId);
		 * logger.info("PC后台发帖结束"); return new
		 * Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, ""); }
		 * catch (Exception e) { logger.error("查询状态发生异常", e); return new
		 * Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage()); } }
		 */

	/**
	 * PC后台发帖
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/publishTopicPC", method = RequestMethod.POST)
	@ApiOperation(value = "PC后台发帖", notes = "PC后台发帖")
	public Response<Map<String, Object>> publishTopicPC(@RequestParam(required = true, defaultValue = "") Long boardId,
			@RequestParam(required = true, defaultValue = "") String topicName,
			@RequestParam(required = true, defaultValue = "") String topicContent,
			// @RequestParam("imgFile") MultipartFile file,
			HttpServletRequest request) throws Exception {
		try {
			logger.info("PC发帖开始");
			// String userId=request.getHeader(ForumConstant.HEADER_USERID);
			String userId = "2";
			logger.info("PC发帖开始，userId为：" + userId);
			TtForumTopic tmForumTopic = new TtForumTopic();
			tmForumTopic.setBoardId(boardId);
			tmForumTopic.setTopicName(topicName);
			tmForumTopic.setTopicContent(topicContent);
			Map<String, Object> result = forumService.publishTopicPC(userId, tmForumTopic, request);
			logger.info("PC发帖发帖结束");
			// Cookie
			// response.addCookie();
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * PC后台评论删除
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/deleteReplyPC", method = RequestMethod.GET)
	@ApiOperation(value = "PC后台评论删除", notes = "PC后台评论删除")
	public Response<Map<String, Object>> deleteReplyPC(@RequestParam(required = true, defaultValue = "") Long replyId,
			@RequestParam(required = true, defaultValue = "") Short deleteFlag, HttpServletRequest request)
			throws Exception {
		try {
			logger.info("PC后台评论删除开始");
			// String userId=request.getHeader(ForumConstant.HEADER_USERID);
			String userId = "2";
			logger.info("PC后台评论删除开始，userId为：" + userId);
			Map<String, Object> result = forumService.deleteReplyPC(userId, replyId, deleteFlag);
			logger.info("PC后台评论删除结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * PC后台版块查询
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryBoardPC", method = RequestMethod.GET)
	@ApiOperation(value = "PC后台版块查询", notes = "PC后台版块查询")
	public Response<List<TmForumBoard>> queryBoardPC(@RequestParam(required = true, defaultValue = "") Long typeId)
			throws Exception {
		try {
			logger.info("PC后台版块查询开始，");
			List<TmForumBoard> result = forumService.queryBoardPC(typeId);
			logger.info("PC后台版块查询结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

	/**
	 * 测试时间
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/testTransFormTime", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "测试时间", notes = "测试时间")
	public Response<String> testTransFormTime(@RequestParam(required = true, defaultValue = "") Date date)
			throws Exception {
		try {
			logger.info("测试时间,date:" + date);
			String result = forumService.transFormTime(date);
			logger.info("PC后台转为资讯结束");
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		}
	}

}
